package com.wibo.account;

import java.util.ArrayList;

import weibo4android.Status;

import com.wibo.common.WeiboItem;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class WeiboListItemAdapter extends BaseAdapter {
	
	private Context mContext;
	private ArrayList<WeiboItem> mItemData;
	
	public WeiboListItemAdapter(Context mContext) {
		super();
		this.mContext = mContext;
	}

	public WeiboListItemAdapter(Context mContext,
			ArrayList<WeiboItem> mItemData) {
		super();
		this.mContext = mContext;
		this.mItemData = mItemData;
	}
	
	public void setAdapterData(ArrayList<WeiboItem> mItemData){
	    this.mItemData = mItemData;
	}
	
	public ArrayList<WeiboItem> getAdapterData(){
		return this.mItemData;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if( mItemData == null ){
			return 0;
		}
		return mItemData.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mItemData.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(mItemData == null ){
            return null;		
    	}
        if(convertView == null){
        	WeiboListItemView itemView = null;

        	itemView = new WeiboListItemView(mContext);

            itemView.updateView(mItemData.get(position), String.valueOf(position));
            convertView = itemView;
        }
        else
        {
            ((WeiboListItemView) convertView).updateView(mItemData.get(position),String.valueOf(position));
        }
    	return convertView;
	}

//	public View getView(int position, View convertView, ViewGroup parent) {
//		ViewHolder holder;
//		if (convertView == null) {
//			convertView = mInflater.inflate(R.layout.list_item_icon_text, null);
//			holder = new ViewHolder();
//			holder.text = (TextView) convertView.findViewById(R.id.text);
//			holder.icon = (ImageView) convertView.findViewById(R.id.icon);
//			convertView.setTag(holder);
//		} else {
//			holder = (ViewHolder) convertView.getTag();
//		}
//		holder.text.setText(DATA[position]);
//		holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
//		return convertView;
//	}
//
//	static class ViewHolder {
//		TextView text;
//		ImageView icon;
//	}
}
